const express = require('express');
const cors = require('cors');
const fileUpload = require('express-fileupload');
const path = require('path');
const authRoutes = require('./routes/auth');

const app = express();

// 中间件配置
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(fileUpload({
    createParentPath: true
}));

// 路由导入
const uploadRoutes = require('./routes/upload');
const paramsRoutes = require('./routes/params');
const trainRoutes = require('./routes/train');

// 注册路由
app.use('/api', uploadRoutes);
app.use('/api', paramsRoutes);
app.use('/api', trainRoutes);
app.use('/api/auth', authRoutes);

// 确保数据目录存在
const dataDir = path.join(__dirname, '../../../FlowTM-main/Data');
const fs = require('fs');
if (!fs.existsSync(dataDir)) {
    fs.mkdirSync(dataDir, { recursive: true });
}

const PORT = process.env.PORT || 3456;
app.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}`);
}); 